<?php

namespace app\common\model\product;
use think\Model;

class ShopProductModel extends Model
{
    // 表名
    protected $name = 'shop_product';
    // 表主键
    protected $pk = 'id';
    const STATUS = [
        ['value' => 0, 'label' => '待付款','code' => 'wait_pay'],
        ['value' => 1, 'label' => '待审核','code' => 'wait_auth'],
        ['value' => 2, 'label' => '审核未通过','code' => 'auth_error'],
        ['value' => 3, 'label' => '进行中','code' => 'in'],
        ['value' => 4, 'label' => '完成','code' => 'success'],
        ['value' => 5, 'label' => '已撤销','code' => 'revoke'],
        ['value' => 6, 'label' => '已暂停','code' => 'stop'],
//        ['value' => 7, 'label' => '已删除','code' => 'del'],
    ];

    /**
     * 查询状态
     * @Author: 易军辉
     * @DateTime:2024-06-07 16:10
     * @param $key 编码或value
     * @param $type 1、查询value  2、查询名称 3、查询编码
     * @return mixed|void
     */
    public static  function getStatus($key,$type=1)
    {
        foreach (self::STATUS as $status) {
            if ($status['code'] == $key || $status['value'] == $key) {
                switch ($type) {
                    case 1:
                        return $status['value']; // 返回value
                    case 2:
                        return $status['label']; // 返回名称
                    default:
                        return $status['code']; // 未知类型，返回null
                }
            }
        }
        return null;
    }
    /**
     * 关联商品（一对多）
     * @Author: 易军辉
     * @DateTime:2024-06-05 12:03
     * @return \think\model\relation\HasMany
     */
    public function productGoods()
    {
        return $this->hasMany(ShopProductGoodsModel::class, 'shop_product_id', 'id');
    }

    /**
     * 关联进店方式
     * @Author: 易军辉
     * @DateTime:2024-06-05 15:22
     * @return \think\model\relation\HasMany
     */
    public function productEnter()
    {
        return $this->hasMany(ShopProductEnterModel::class, 'shop_product_id', 'id');
    }

    /**
     * 关联放单计划
     * @Author: 易军辉
     * @DateTime:2024-06-05 16:03
     * @return \think\model\relation\HasMany
     */
    public function productRelease()
    {
        return $this->hasMany(ShopProductReleaseModel::class, 'shop_product_id', 'id');
    }

    /**
     * 关联增值服务
     * @Author: 易军辉
     * @DateTime:2024-06-06 10:08
     * @return \think\model\relation\HasMany
     */
    public function productIncrement()
    {
        return $this->hasMany(ShopProductIncrementModel::class, 'shop_product_id', 'id');
    }

    /**
     *关联费用明细
     * @Author: 易军辉
     * @DateTime:2024-06-06 14:34
     * @return \think\model\relation\HasMany
     */
    public function productPrice()
    {
        return $this->hasMany(ShopProductPriceModel::class, 'shop_product_id', 'id');
    }
}
